home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / visulztn / lise / minilise.lha / minilise / spec.h < prev    next >
C/C++ Source or Header  |  1993-03-30  |  19KB  |  617 lines

  1. /* This include file handles spectra input, output and some specific
  2.    comandline parsing. Routines supported:
  3.    xmax=readspec(name,float[8192],error[8192],time[8192],string)
  4.            reads the spectrum specified and
  5.            returns the number of relevant channels.
  6.            Spectra files can have the pure name supported,
  7.            or have the extension ".spc".
  8.            Error arrays are identified by the extension ".err".
  9.       Time arrays are identified by the extension ".tim".
  10.             Spectra may be specified with a range. eg. spc[100:300].
  11.    result=checkopt(argc,argv,"string",stringvar)
  12.            checks for the specified options, and returns true or false
  13.            and the following string variable.
  14.    writespec(name,float_array,error_array,xmax,typ,stringcomment)
  15.       name is a string containing the name of the spectrum,
  16.            typ is 0 for I2 spectra, 1 for I4 spectra and 2 for R4 spectra.
  17.       If "1" is specified, then all data is saved as ASCII integer,
  18.       while "2" denotes ASCII float.
  19.    outspec(stream,float_array,xmax,typ,stringcomment)
  20.  
  21.    special care is taken, so that CPU (intel!) specific dependencies
  22.    on binary formats should not occur.
  23.    Options -i  (Integer ASCII output),
  24.            -r  (float ASCII output),
  25.            -i2 (short integer binary),
  26.            -i4 (long integer binary),
  27.            -r4 (float binary, NOT SUPPORTED yet),
  28.            -o name (output goes to files [.spc and .err] and not to stdout)
  29.            -h  (call help routine)
  30.            -help (call help routine)
  31.            -p n (sets grafic pipe number)
  32.            -n (specifies a subwindow)
  33.    are checked when checkopt is called.
  34.    Notice, that a help() routine must be present in every program !
  35.  
  36.                                           Programmer: RAKO
  37. */
  38.  
  39. #include <math.h>
  40. #include <strings.h>
  41. #ifdef ICON_ON
  42. #include <workbench/workbench.h>
  43. #include <workbench/icon.h>
  44. #endif
  45.  
  46. #ifndef TRUE
  47. #define TRUE 1L
  48. #endif
  49. #ifndef FALSE
  50. #define FALSE 0L
  51. #endif
  52.  
  53. #ifndef _SPECHDR
  54. #define _SPECHDR
  55.  
  56. int   _spc_outflg = -2,      /* signal "option not checked"  */
  57.       _tekpipe = 0,
  58.       _win_flg = 0,
  59.       _sbeg , _send , _max,
  60.       _lise_err = 0;
  61. int _MAXSPCLEN = 2048;       /* was a constant before */
  62. char  *_spc_onam = NULL,
  63.       *_spc_0nam = NULL;
  64. float _tica=1.0,
  65.       *_uspc = NULL,
  66.       *_uerr = NULL,
  67.       *_utim = NULL;
  68.  
  69.  
  70.  
  71. void _help0()    /* call user help(), print out standard message and exit */
  72. {
  73. help();
  74. printf("\nstandard spectra options:\n");
  75. printf(" -i  (Integer ASCII output), \n");
  76. printf(" -r  (float ASCII output),\n");
  77. printf(" -i2 (short integer binary),\n");
  78. printf(" -i4 (long integer binary),\n");
  79. printf(" -r4 (float binary, !! NOT PORTABLE !! yet),\n");
  80. printf(" -wsimple (write ASCII simple spectrum)\n");
  81. printf(" -o name (output goes to files [.spc and .err] and not to stdout)\n");
  82. printf(" -h  (call help routine)\n");
  83. printf(" -help (call help routine)\n");
  84. printf(" -p n (sets grafic pipe number)\n");
  85. printf(" -n  (n=0..6 specifies a subwindow)\n\n");
  86. #ifdef MAINVERSION
  87. printf("LISE Version %s\n",MAINVERSION);
  88. #endif
  89. #ifdef CREATIONDATE
  90. printf("last modified at %s\n",CREATIONDATE);
  91. #endif
  92. printf("Maximum spectra length is %d\n",_MAXSPCLEN);
  93. printf("set the environment variable MAXSPCLEN to change from default\n");
  94. printf("initial idea and implementations for UNIX and AMIGA by Rainer Kowallik\n");
  95. exit(0);
  96. }
  97.  
  98. float atosf(s)
  99. char s[];
  100. {
  101. double atof();
  102. float y;
  103.  
  104.    y=atof(s);
  105.    return(y);
  106. }
  107.  
  108. checkopt(argc,argv,s,sv)
  109. int argc;
  110. char *argv[],s[],sv[];
  111. {
  112. int   n,erg;
  113. char  *z,*env;
  114.  
  115.    z = (char *) malloc(80);
  116.    if(_spc_outflg==-2) {
  117.       _spc_outflg = -1;        /* signal "no ouput option specified" */
  118.       env = (char *) getenv("MAXSPCLEN");
  119.       if(env != NULL) _MAXSPCLEN = atoi(env);
  120.       if(_uspc == NULL) _uspc = (float *) calloc(_MAXSPCLEN,sizeof(float));
  121.       if(_uerr == NULL) _uerr = (float *) calloc(_MAXSPCLEN,sizeof(float));
  122.       if(_utim == NULL) _utim = (float *) calloc(_MAXSPCLEN,sizeof(float));
  123.       if(_spc_onam == NULL) _spc_onam = (char *) malloc(80);
  124.       if(_spc_0nam == NULL) _spc_0nam = (char *) malloc(80);
  125.       strcpy(_spc_onam,"");    /* signal "no output file names */
  126.       if(checkopt(argc,argv,"-h",z)) _help0();
  127.       if(checkopt(argc,argv,"-help",z)) _help0();
  128.       if(checkopt(argc,argv,"-i",z)) _spc_outflg='1';
  129.       if(checkopt(argc,argv,"-r",z)) _spc_outflg='2';
  130.       if(checkopt(argc,argv,"-i2",z)) _spc_outflg=0;
  131.       if(checkopt(argc,argv,"-i4",z)) _spc_outflg=1;
  132.       if(checkopt(argc,argv,"-r4",z)) _spc_outflg=2;
  133.       if(checkopt(argc,argv,"-wsimple",z)) _spc_outflg = ' ';
  134.       if(checkopt(argc,argv,"-0",z)) _win_flg=0;
  135.       if(checkopt(argc,argv,"-1",z)) _win_flg=1;
  136.       if(checkopt(argc,argv,"-2",z)) _win_flg=2;
  137.       if(checkopt(argc,argv,"-3",z)) _win_flg=3;
  138.       if(checkopt(argc,argv,"-4",z)) _win_flg=4;
  139.       if(checkopt(argc,argv,"-5",z)) _win_flg=5;
  140.       if(checkopt(argc,argv,"-6",z)) _win_flg=6;
  141.       if(checkopt(argc,argv,"-o",z)) strcpy(_spc_onam,z);
  142.       if(checkopt(argc,argv,"-p",z)) _tekpipe=atoi(z);
  143.    }
  144.    erg=FALSE;
  145.    for(n=1;n<argc;n++) {
  146.       if(strcmp(argv[n],s)==0) {
  147.          erg=TRUE;
  148.          if((n + 1) < argc) strcpy(sv,argv[n+1]);
  149.       }
  150.    }
  151.    free(z);
  152.    return(erg);
  153. }
  154.  
  155. specin(stream,spc,s)
  156. FILE *stream;
  157. char s[];
  158. float spc[];
  159. {
  160. unsigned char byte1,byte2;
  161. char        c,z[80];
  162. int         typ,n,max;
  163. unsigned long int m;
  164. union    fourbytes {
  165.             float                real;
  166.             long int             sig;
  167.             unsigned long int    card;
  168.          } b4;
  169. union    twobytes {
  170.             short int            sig;
  171.             unsigned short int   card;
  172.          } b2;
  173.  
  174.    byte1=fgetc(stream);
  175.    if(byte1 == ' ') {               /* handle simple ASCII (MUST start with a blank)  */
  176.       max = 0;
  177.       _tica = 1.0;
  178.       strcpy(s,"");
  179.       while(!feof(stream)) {
  180.          fscanf(stream,"%s\n",z);
  181.          spc[max++] = atosf(z);
  182.       }
  183.       return(max);
  184.    }
  185.  
  186.    if(byte1==0) {                   /* binary spectra formats */
  187.       byte2=fgetc(stream);
  188.       if(byte2 > 3) {
  189.          fprintf(stderr,"%c  %d\n",byte2,byte2);
  190.          fprintf(stderr,"spectra i/o:\n not a bin spectra file !\n");
  191.          lise_exit(-1); return(-1);
  192.       }
  193.       typ=byte1*256+byte2; /* MSB LSB ! spectrum type */
  194.       byte1=fgetc(stream); byte2=fgetc(stream);
  195.       max=byte1*256+byte2; /* spectrum length in channels */
  196.       for(n=0;n<=79;n++) {    /* read comment */
  197.          s[n]=fgetc(stream);
  198.          if(s[n]==0) continue;
  199.          if(s[n]<32) s[n]=32;
  200.       }
  201.       m=0;                    /* read time calibration factor */
  202.       m = fgetc(stream);
  203.       m = (m << 8) + fgetc(stream);
  204.       m = (m << 8) + fgetc(stream);
  205.       m = (m << 8) + fgetc(stream);
  206.       b4.card=m; _tica=b4.real;
  207.  
  208.       for(n=1;n<=8;n++) c=fgetc(stream); /* skip 4 spare words */
  209.    } else {                   /* ASCII spectra formats */
  210.       typ=byte1;
  211.       if((byte1 != '1') && (byte1 != '2')) {
  212.          fprintf(stderr,"%c  %d\n",byte1,byte1);
  213.          fprintf(stderr,"spectra i/o:\n not an ASCII spectra file !\n");
  214.          lise_exit(-1); return(-1);
  215.       }
  216.       c=0; while(c!='\n') c=fgetc(stream);
  217.       fscanf(stream,"%d\n",&max);            /* read number of channels */
  218.       n=0; c=0; while(c!='\n') {             /* read comment */
  219.          c=fgetc(stream) ; s[n++]=c;
  220.       }
  221.       s[n]=0;
  222.       fscanf(stream,"%s\n",z);
  223.       _tica=atosf(z);                       /* read time calibration */
  224.       fscanf(stream,"\n\n\n\n");
  225.    }
  226.    n=0;
  227.    switch(typ) {
  228.    case 0:                 /* binary short integer */
  229.       for(n=0;n<max;n++) {
  230.          if(feof(stream)) {
  231.             max=n;         /* trap too few elements */
  232.             break;
  233.          }
  234.          byte1=fgetc(stream);
  235.          byte2=fgetc(stream);
  236.          b2.card = (byte1 << 8) + byte2;
  237.          spc[n]=b2.sig;
  238.       }
  239.       break;
  240.    case 1:                 /* binary long integer */
  241.       for(n=0;n<max;n++) {
  242.          if(feof(stream)) {
  243.             max=n;         /* trap too few elements */
  244.             break;
  245.          }
  246.          m = fgetc(stream);
  247.          m = (m << 8) + fgetc(stream);
  248.          m = (m << 8) + fgetc(stream);
  249.          m = (m << 8) + fgetc(stream);
  250.          b4.card=m;
  251.          spc[n]=b4.sig;
  252.       }
  253.       break;
  254.    case 2:                         /* binary float */
  255.       for(n=0;n<max;n++) {
  256.          if(feof(stream)) {
  257.             max=n;         /* trap too few elements */
  258.             break;
  259.          }
  260.          m = fgetc(stream);
  261.          m = (m << 8) + fgetc(stream);
  262.          m = (m << 8) + fgetc(stream);
  263.          m = (m << 8) + fgetc(stream);
  264.          b4.card=m;
  265.          spc[n]=b4.real;
  266.       }
  267.       break;
  268.    case '1':                       /* ASCII integer */
  269.       for(n=0;n<max;n++) {
  270.          if(feof(stream)) {
  271.             max=n;         /* trap too few elements */
  272.             break;
  273.          }
  274.          fscanf(stream,"%d\n",&m);
  275.          spc[n]=m;
  276.       }
  277.       break;
  278.    case '2':                        /* ASCII float */
  279.       for(n=0;n<max;n++) {
  280.          if(feof(stream)) {
  281.             max=n;         /* trap too few elements */
  282.             break;
  283.          }
  284.          fscanf(stream,"%s\n",z);
  285.          spc[n]=atosf(z);
  286.       }
  287.       break;
  288.    }
  289.    return(max);
  290. }
  291.  
  292. readspec(snam,spc,err,tim,s)
  293. char snam[],s[];
  294. float spc[],err[],tim[];
  295. {
  296. FILE        *stream,*fopen();
  297. char        *fnam2,*range,*z;
  298. int         io_flg,i,j,n,max;
  299. float       x;
  300.  
  301.  
  302.    if(_spc_onam == NULL) _spc_onam = (char *) malloc(80);
  303.    if(_spc_0nam == NULL) _spc_0nam = (char *) malloc(80);
  304.  
  305.    fnam2 = (char *) malloc(80);
  306.    range = (char *) malloc(80);
  307.    z = (char *) malloc(80);
  308.  
  309.    if(_uspc == NULL) _uspc = (float *) calloc(_MAXSPCLEN,sizeof(float));
  310.    if(_uerr == NULL) _uerr = (float *) calloc(_MAXSPCLEN,sizeof(float));
  311.    if(_utim == NULL) _utim = (float *) calloc(_MAXSPCLEN,sizeof(float));
  312.  
  313.    io_flg=0;
  314.  
  315.    n=strlen(snam);
  316.    if((n>0) && (n<80) && snam[0]!='-') {       /* do the parsing */
  317.       j=instr("[",snam);
  318.       if(j>0) {
  319.          midstr(_spc_0nam,snam,0,j-1);
  320.          midstr(range,snam,j+1,instr("]",snam)-1);
  321.       } else {
  322.          strcpy(_spc_0nam,snam);
  323.          strcpy(range,"");
  324.       }
  325.       i=instr(":",range);
  326.       if(strlen(range)==0) { /* handle spc[] */
  327.          _sbeg=0;
  328.          _send=_MAXSPCLEN;
  329.          io_flg=1;
  330.       } else {
  331.          if(i<0) {             /* handle spc[n] */
  332.             _sbeg=atoi(range);
  333.             _send=_sbeg;
  334.             io_flg=1;
  335.          }
  336.          if(i>0) {
  337.             midstr(z,range,0,i-1); _sbeg=atoi(z);
  338.             midstr(z,range,i+1,strlen(range)); _send=atoi(z);
  339.             io_flg=1;
  340.          }
  341.          if(i==0) {
  342.             _sbeg=0;
  343.             midstr(z,range,i+1,strlen(range)); _send=atoi(z);
  344.             io_flg=1;
  345.          }
  346.       }
  347.    }
  348.  
  349.    j=instr(".spc",_spc_0nam);                   /* removing superflous .spc */
  350.    if(j>0) {
  351.       midstr(z,_spc_0nam,0,j-1);
  352.       strcpy(_spc_0nam,z);
  353.    }
  354.  
  355.  
  356.  
  357.    if(_sbeg > _send) {                           /* trapping obvious errors */
  358.       fprintf(stderr,"starting channel higher than last channel !\n");
  359.       lise_exit(-1); free(fnam2); free(range); free(z); return(-1);
  360.    }
  361.    if(_send > _MAXSPCLEN) {
  362.       fprintf(stderr,"sorry, this LIESE Version can only handle spectra\n");
  363.       fprintf(stderr,"up to %d channels\n", _MAXSPCLEN);
  364.       lise_exit(-1); free(fnam2); free(range); free(z); return(-1);
  365.    }
  366.  
  367.                                                       /* now read the data */
  368.    if(io_flg==0) { /* reading from stdin */
  369.       max=specin(stdin,_uspc,s);
  370.    }
  371.    if(io_flg==1) { /* reading from file, possible error and time arrays */
  372.       strcpy(fnam2,_spc_0nam); strcpy(z,_spc_0nam);
  373.       stream=fopen(z,"r");
  374.       if(stream==NULL) {
  375.          strcat(z,".spc");
  376.          stream=fopen(z,"r");
  377.          if(stream==NULL) {
  378.  fprintf(stderr,"spectra i/o:\n unable to open file for read %s\n",_spc_0nam);
  379.             lise_exit(-1); free(fnam2); free(range); free(z); return(-1);
  380.          }
  381.       }
  382.       max=specin(stream,_uspc,s);                /* first read data */
  383.    }
  384.    _max=max; /* tell it to the user */
  385.    fclose(stream);
  386.    x = _tica;                                    /* get time calibration */
  387.    stream=fopen("tica.all","r");                 /* try to read another tica */
  388.    if(stream!=NULL) {
  389.       fscanf(stream,"%s\n",z);
  390.       x=atosf(z);
  391.       fclose(stream);
  392.    }
  393.    for(n=0;n<_MAXSPCLEN;n++) {                   /* preset time and error */
  394.       _uerr[n] = 0.0;
  395.       _utim[n] = n * x ;
  396.    }
  397.  
  398.    if(io_flg==1) { /* reading from file, possible error and time arrays */
  399.       strcpy(z,_spc_0nam); strcat(z,".err");
  400.       stream=fopen(z,"r");
  401.       if(stream!=0) {                        /* read error array */
  402.          specin(stream,_uerr,z);
  403.          fclose(stream);
  404.       }      strcpy(z,_spc_0nam); strcat(z,".tim");
  405.       stream=fopen(z,"r");
  406.       if(stream!=0) {                       /* read time array */
  407.          specin(stream,_utim,z);
  408.          fclose(stream);
  409.       }
  410.       i=0; n=_sbeg;
  411.       _tica = x; /* value from *.spc should overwrite value from *.err */
  412.       while(n<=_send) {                   /* cut specified range */
  413.          spc[i]=_uspc[n];
  414.          err[i]=_uerr[n];
  415.          tim[i]=_utim[n];
  416.          i=i+1; n=n+1;
  417.       }
  418.       if((_send-_sbeg)<max) {
  419.          max=_send-_sbeg+1;
  420.       }
  421.    }
  422.    free(fnam2); free(range); free(z); return(max);
  423. }
  424.  
  425. putreal(stream,x)
  426. FILE *stream;
  427. float x;
  428. {
  429. unsigned char byte1,byte2,byte3,byte4;
  430. unsigned long int m;
  431. union    fourbytes {
  432.             float                real;
  433.             long int             sig;
  434.             unsigned long int    card;
  435.          } b4;
  436.  
  437.          b4.real=x; m=b4.card;
  438.                     byte1 = m >> 24 ;
  439.                     byte2 = (m >> 16) & 255 ;
  440.                     byte3 = (m >> 8) & 255 ;
  441.                     byte4 = m & 255;
  442.          fputc(byte1,stream); fputc(byte2,stream);
  443.          fputc(byte3,stream); fputc(byte4,stream);
  444.    return(0);
  445. }
  446.  
  447. outspec(stream,spc,max,typ1,s)
  448. char     s[];
  449. float    spc[];
  450. int      max,typ1;
  451. FILE     *stream;
  452. {
  453. unsigned char byte1,byte2,byte3,byte4;
  454. int      n,typ;
  455. char     *z;
  456. unsigned long int m;
  457. union    fourbytes {
  458.             float                real;
  459.             long int             sig;
  460.             unsigned long int    card;
  461.          } b4;
  462. union    twobytes {
  463.             short int            sig;
  464.             unsigned short int   card;
  465.          } b2;
  466.  
  467.    z = (char *) malloc(80);
  468.  
  469.    typ=typ1;
  470.    if(_spc_outflg >= 0) typ=_spc_outflg;        /* force user requested output */
  471.  
  472.    switch(typ) {
  473.    case 0:                                      /* binary short integer */
  474.       fputc(0,stream); fputc(typ,stream);       /* write type     */
  475.       byte1 = max >> 8 ; byte2 = max & 255;
  476.       fputc(byte1,stream); fputc(byte2,stream); /* write length in channels */
  477.       for(n=0;n<80;n++) fputc(s[n],stream);     /* write comment  */
  478.       putreal(stream,_tica);                    /* time calibration */
  479.       for(n=1;n<=8;n++) fputc(0,stream);        /* 4 spare words  */
  480.       for(n=0;n<max;n++) {                      /* write data     */
  481.          b2.sig=spc[n]; m=b2.card;
  482.          byte1 = m >> 8; byte2= m & 255;
  483.          fputc(byte1,stream); fputc(byte2,stream);
  484.       }
  485.       break;
  486.    case 1:                                      /* binary long integer */
  487.       fputc(0,stream); fputc(typ,stream);       /* write type     */
  488.       byte2 = max & 255 ; byte1 = max >> 8;
  489.       fputc(byte1,stream); fputc(byte2,stream); /* write length in channels */
  490.       for(n=0;n<80;n++) fputc(s[n],stream);     /* write comment  */
  491.       putreal(stream,_tica);                    /* time calibration */
  492.       for(n=1;n<=8;n++) fputc(0,stream);        /* 4 spare words  */
  493.       for(n=0;n<max;n++) {                      /* write data     */
  494.          b4.sig=spc[n]; m=b4.card;
  495.                     byte1 = m >> 24 ;
  496.                     byte2 = (m >> 16) & 255 ;
  497.                     byte3 = (m >> 8) & 255 ;
  498.                     byte4 = m & 255;
  499.          fputc(byte1,stream); fputc(byte2,stream);
  500.          fputc(byte3,stream); fputc(byte4,stream);
  501.       }
  502.       break;
  503.    case 2:                 /* binary float */
  504.       fputc(0,stream); fputc(typ,stream);       /* write type     */
  505.       byte1 = max >> 8 ; byte2 = max & 255;
  506.       fputc(byte1,stream); fputc(byte2,stream); /* write length in channels */
  507.       for(n=0;n<80;n++) fputc(s[n],stream);     /* write comment  */
  508.       putreal(stream,_tica);                    /* time calibration */
  509.       for(n=1;n<=8;n++) fputc(0,stream);        /* 4 spare words  */
  510.       for(n=0;n<max;n++) putreal(stream,spc[n]);
  511.       break;
  512.    case '1':               /* ASCII integer */
  513.       fprintf(stream,"1\n%d\n%s\n%E\n\n\n\n\n",max,s,_tica);
  514.       for(n=0;n<max;n++) {m=spc[n]; fprintf(stream,"%d\n",m);}
  515.       break;
  516.    case '2':               /* ASCII float */
  517.       fprintf(stream,"2\n%d\n%s\n%E\n\n\n\n\n",max,s,_tica);
  518.       for(n=0;n<max;n++) fprintf(stream,"%E\n",spc[n]);
  519.       break;
  520.    case ' ' :               /* simple ASCII */
  521.       for(n = 0; n < max; n++) fprintf(stream," %f\n",spc[n]);
  522.       break;
  523.    }
  524.    free(z);
  525.    return(0);
  526. }
  527.  
  528. writespec(name0,spc,err,max,typ,s)
  529. char     name0[],s[];
  530. float    spc[],err[];
  531. int      max,typ;
  532. {
  533. int      n;
  534. char     *z,*name;
  535. FILE     *stream,*fopen();
  536. #ifdef ICON_ON
  537. struct DiskObject *object;
  538. #endif
  539.  
  540.    z = (char *) malloc(80);
  541.    name = (char *) malloc(80);
  542.  
  543.    n=instr(".tim",name0);
  544.    if(n>0) {                     /* write only time spectrum */
  545.       stream=fopen(name0,"w");
  546.       outspec(stream,spc,max,typ,s);
  547. #ifdef UNIX
  548.    chmod(z,0666);
  549. #endif
  550.       fclose(stream);
  551.       free(name); free(z);
  552.       return(0);
  553.    }
  554.    n=instr(".err",name0);
  555.    if(n>0) {                     /* write only error spectrum */
  556.       stream=fopen(name0,"w");
  557.       outspec(stream,spc,max,typ,s);
  558.       fclose(stream);
  559. #ifdef UNIX
  560.    chmod(z,0666);
  561. #endif
  562.       free(name); free(z);
  563.       return(0);
  564.    }
  565.    strcpy(name,name0);
  566.    if(strlen(_spc_onam)>0) strcpy(name,_spc_onam);
  567.    if(strlen(name)==0) {
  568.       outspec(stdout,spc,max,typ,s);
  569.       free(name); free(z);
  570.       return(0);
  571.    }
  572.    strcpy(z,name); strcat(z,".spc");
  573.    stream=fopen(z,"w");
  574.    if(stream==NULL) {
  575.       fprintf(stderr,"spectra io:\n can not open file for write %s\n",z);
  576.       free(name); free(z);
  577.       return(-1);
  578.    }
  579.    outspec(stream,spc,max,typ,s);
  580.    fclose(stream);
  581. #ifdef UNIX
  582.    chmod(z,0666);
  583. #endif
  584.    strcpy(z,name); strcat(z,".err");
  585.    stream=fopen(z,"w");
  586.    if(stream==NULL) {
  587.       fprintf(stderr,"spectra io:\n can not open file for write %s\n",z);
  588.       free(name); free(z);
  589.       return(-1);
  590.    }
  591.    outspec(stream,err,max,typ,s);
  592.    fclose(stream);
  593. #ifdef UNIX
  594.    chmod(z,0666);
  595. #endif
  596. #ifdef ICON_ON
  597.    object = GetDiskObject("LISE:Spectrum_Default"); /* generate Icon for Spectrum */
  598.    if(object == NULL) return(0);
  599.    object->do_Magic = WB_DISKMAGIC;
  600.    object->do_Version = WB_DISKVERSION;
  601.    object->do_CurrentX = NO_ICON_POSITION;
  602.    object->do_CurrentY = NO_ICON_POSITION;
  603.    strcpy(z,name); strcat(z,".spc");
  604.    PutDiskObject(z,object);
  605.    FreeDiskObject(object);
  606. #endif
  607.    free(name); free(z);
  608. }
  609. lise_exit(n)
  610. int n;
  611. {
  612.    if(_lise_err == 0) exit(n);
  613.    _lise_err = n;
  614.    return(0);
  615. }
  616. #endif
  617.